<template>
    <div id="myChart" :style="{width: '100%', height: '300px'}"></div>
</template>

<script>
    export default {
        name: "lineCharts",
        props:['nameList','saleList'],
        data () {
            return {

            }
        },
        mounted(){
            this.drawLine();
        },
        methods: {
            drawLine(){
                // 基于准备好的dom，初始化echarts实例
                // console.log(this.nameList,this.saleList);
                let myChart = this.$echarts.init(document.getElementById('myChart'))
                // 绘制图表
                myChart.setOption({
                    title: { text: '商品销量排行' },
                    tooltip: {},
                    xAxis: {
                        data: this.nameList
                    },
                    yAxis: {},
                    series: [{
                        name: '销量',
                        type: 'bar',
                        data: this.saleList
                    }]
                });
            }
        }
    }
</script>

<style scoped>
    #myChart{
        width: 100%;
        box-sizing: border-box;
        background-color: #fff;
        padding:20px;
        border-radius: 10px;
    }
</style>
